//取app.jszhongdeshuju
var app = getApp()
const HOST = app.globalData.host

Page({
  imgUrls:[
    "/pages/images/haibao/1.jpg",
    "/pages/images/haibao/2.jpg",
    "/pages/images/haibao/3.jpg",
  ],
  data: {
    currentTab: 0,
    books:[],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      currentTab: options.type
    })
    wx.showTabBarRedDot({
      index: 1,
    })
    wx.setTabBarBadge({
      index: 2,
      text: 'aa',
    })
    wx.showLoading()  
    this.getBookList(options.type);
  },
  getBookList(type){
    var page = this
    wx.request({
      url: HOST+'/api/goods/getHomeGoodsList',
      method:'GET',
      data:{
        type
      },
      success(res){
        console.log(res)
        // page.data.rmjsList = res.data.data.rmjs
        page.setData({
          rmjsList:res.data.data.rmjs,
          msskList:res.data.data.mssk,
          cxsjList:res.data.data.cxsj
        })
      },
      complete(){
        wx.hideLoading({
          
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   /*  wx.showToast({
      title: 'index',
      icon:'success',
      duration:3000
    }) */
  },
  switchNav(e){
    var page = this;
    var type = e.target.dataset.current;
    if(this.data.currentTab==type){
        return false;
    }else{
        page.setData({
            currentTab:type
        });
        this.getBookList(type)
    }
},

getBookList(type) {
    var page = this;
    wx.request({
      url:HOST + '/api/goods/getGoodsListByType',
      method: 'GET',
      data: { type: type},
      success(res) {
        var books = res.data.data;
        console.log(books);
        page.setData({ books: books });
      },
      complete() {
        wx.hideLoading()
      }
    })
  },
  scroll(e){
  /*   if (e.detail.scrollTop>=300) {
      this.onShow()
    } */
  },
  upper(){

  },
  lower(){

  },

  change(e) {
    console.log(e.detail)
  },

  tap(e) {
      let id = e.target.dataset.id
      this.setData({
        current: id
      })

      
  } 
})